<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.48">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Helvetica; color: #000000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial; color: #000000; background-color: #f9f9f9; min-height: 15.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial; color: #000000; background-color: #f9f9f9}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #000000}
span.s3 {color: #0000bf}
span.s4 {color: #bf0000}
span.s5 {color: #007300}
span.s6 {color: #606060}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>FormantTable<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></b></span><b>Lookup table for emulating vocal tracts</b></p>
<p class="p2"><br></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>FormantTable.get(preset)</b></p>
<p class="p2"><br></p>
<p class="p3">Returns a set of frequencies+resonances+amplitudes for a set of 5 bandpass filters, useful for emulating the main 5 formants of a vocal tract. To see the available voice types run this line:</p>
<p class="p2"><br></p>
<p class="p4">FormantTable.keys</p>
<p class="p2"><br></p>
<p class="p3"><b>Examples</b></p>
<p class="p3">(by Eric Skogen)</p>
<p class="p2"><br></p>
<p class="p5">// first boot the server</p>
<p class="p4">s.boot;</p>
<p class="p6"><br></p>
<p class="p5">// Saw freq is controlled by mouse X position</p>
<p class="p5">// BBandPass filter is controlled by</p>
<p class="p5">//    FormantTable data (frequencies, resonances, amplitudes)</p>
<p class="p4">(</p>
<p class="p7"><span class="s2"><span class="Apple-tab-span">	</span></span><span class="s3">SynthDef</span><span class="s2">(</span>\formantVoice<span class="s2">, { </span><span class="s3">arg</span></p>
<p class="p4">              f = #[ 400, 750, 2400, 2600, 2900 ],</p>
<p class="p4">              a = #[ 1, 0.28183829312645, 0.089125093813375, 0.1, 0.01 ],</p>
<p class="p4">              q = #[ 0.1, 0.10666666666667, 0.041666666666667,</p>
<p class="p4">                      0.046153846153846, 0.041379310344828 ];</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> scale = [0, 2, 4, 7, 9]; <span class="s4">// pentatonic major</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> scaleBuf = <span class="s3">LocalBuf</span>(scale.size, 1).set(scale);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> degree = <span class="s3">Index</span>.kr(scaleBuf, <span class="s3">MouseX</span>.kr(0, <span class="s3">BufFrames</span>.kr(scaleBuf)));</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> vibrato = <span class="s3">SinOsc</span>.kr(6, mul:4);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> base = 4 * 12;</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> in = <span class="s3">Saw</span>.ar(((degree + base).midicps + vibrato).lag(0.3));</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">Out</span>.ar(0, <span class="s3">Mix</span>.new(<span class="s3">BBandPass</span>.ar(in, f, q) * a).dup);</p>
<p class="p4">  }).send(s);</p>
<p class="p4">)</p>
<p class="p6"><br></p>
<p class="p5">// create a menu of the FormantTable options for preview</p>
<p class="p4">(</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> voices = <span class="s3">FormantTable</span>.keys.asArray;</p>
<p class="p4"><span class="Apple-tab-span">	</span>voices.sort;</p>
<p class="p6"><br></p>
<p class="p5"><span class="s2"><span class="Apple-tab-span">	</span></span>// start an instance of the synth</p>
<p class="p4"><span class="Apple-tab-span">	</span>#f, a, q = <span class="s3">FormantTable</span>.get( voices.first );</p>
<p class="p4"><span class="Apple-tab-span">	</span>x = <span class="s3">Synth</span>(<span class="s5">\formantVoice</span>, [<span class="s5">\f</span>, f, <span class="s5">\a</span>, a, <span class="s5">\q</span>, q]);</p>
<p class="p8"><span class="s2"><span class="Apple-tab-span">	</span>w = </span><span class="s3">Window</span><span class="s2">(</span>"FormantTable Browser"<span class="s2">,</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s3">Rect</span>(<span class="s3">Window</span>.screenBounds.width/2 - 150,</p>
<p class="p4">              <span class="s3">Window</span>.screenBounds.height/2 - 30,</p>
<p class="p4">              300, 60));</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">StaticText</span>(w, <span class="s3">Rect</span>(0, 5, w.view.bounds.width, 20))</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>.font_(<span class="s3">Font</span>(<span class="s6">"Helvetica"</span>, 11))</p>
<p class="p8"><span class="s2"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>.string_(</span>"Move mouse left/right to change pitch"<span class="s2">)</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>.align_(<span class="s5">\center</span>);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">PopUpMenu</span>(w, w.view.bounds.insetBy(15, 20).moveBy(0, 10))</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>.items_(voices)</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>.action_({ <span class="s3">|v|</span></p>
<p class="p5"><span class="s2"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></span>// change the data based on user action</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>#f, a, q = <span class="s3">FormantTable</span>.get( v.item );</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>x.setn(<span class="s5">\f</span>, f);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>x.setn(<span class="s5">\a</span>, a);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>x.setn(<span class="s5">\q</span>, q);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>});</p>
<p class="p4"><span class="Apple-tab-span">	</span>w.onClose_({ x.free });</p>
<p class="p4"><span class="Apple-tab-span">	</span>w.front;</p>
<p class="p4">)</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p5">// A laughter generator</p>
<p class="p5">// NB mac-only at the moment, sorry</p>
<p class="p4">(</p>
<p class="p4">#f, a, q = <span class="s3">FormantTable</span>.get(<span class="s5">\altoA</span>);</p>
<p class="p4">e = <span class="s3">Env</span>(</p>
<p class="p4">[ 1.6315789222717, 2.8684210777283, 0, 1.1526317596436, 0, 0.63157892227173, 0, 0, 0.39473664164831, 0.41710549016785, 0, 0.33685091589462, 0.3538348548878, 0, 0.10526323318481, 0 ],</p>
<p class="p4">[ 0.099179289557717, 0.029608596454967, 0.070896452123469, 0.015656579624523, 0.045265132730657, 0.08636364069852, 0.027344267630401, 0.021196740851856, 0.025568173912275, 0.020519098486223, 0.029819674626466, 0.025645296259773, 0.057419430367461, 0.18465909090909, 0.16357317837802 ]</p>
<p class="p4">);</p>
<p class="p4">w = <span class="s3">Window</span>(<span class="s6">"Laugh Editor"</span>, <span class="s3">Rect</span>(200,200,400,300));</p>
<p class="p4">v = <span class="s3">SCEnvelopeEdit</span>(w, w.view.bounds.moveBy(20,20).resizeBy(-40,-140), e, 20).resize_(5);</p>
<p class="p4">b = <span class="s3">Button</span>(w, w.view.bounds.moveBy(20,200).resizeBy(-40,-240)).states_([[<span class="s6">"Laugh"</span>]]).resize_(5)</p>
<p class="p4">  .action_({</p>
<p class="p4">      x = {</p>
<p class="p4">          <span class="s3">var</span> saw = <span class="s3">Saw</span>.ar((<span class="s3">EnvGen</span>.kr(v.env, doneAction:2) * 440)); <span class="s4">// lazy</span></p>
<p class="p4">          <span class="s3">var</span> out = <span class="s3">Mix</span>.new(<span class="s3">BBandPass</span>.ar(saw, f, q) * a).dup;</p>
<p class="p4">          <span class="s3">HPF</span>.ar(out, 250); <span class="s4">// avoid blowups</span></p>
<p class="p4">      }.play;</p>
<p class="p4">  });</p>
<p class="p4">w.front;</p>
<p class="p4">)</p>
<p class="p6"><br></p>
</body>
</html>
